package com.test.listenerevent;

import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * @Author zz-lxf
 * @E-mail 629938044@qq.com
 * @Date 2021/12/3 10:59
 * @Version 1.0
 */
@Component
public class DmzListener {

    /**
     * 添加一个监听器
     * phase = TransactionPhase.AFTER_COMMIT意味着这个方法在事务提交后执行
     * @param transactionEvent
     */
    @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
//    @EventListener
    public void listen(DmzTransactionEvent transactionEvent) {
        System.out.println(transactionEvent.getSource().toString());
        System.out.println("事务已提交");
    }
}
